<?
           
require('./includes/config.inc.php');
  
     $TIME = mktime(date("H")+$SETTINGS['timecorrection'],date("i"),date("s"),date("m"), date("d"),date("Y"));

$NOW = date("YmdHis",$TIME);
  
  
 $auction_id = intval($_GET['id']); 
$id2 = $_SESSION["PHPAUCTION_LOGGED_IN"];
 

  
 if($id2) {
 
 
 
 
  $query = mysql_fetch_array(mysql_query("SELECT bids_remaining FROM PHPAUCTIONXL_users WHERE id=$id2 "));
  
  $jsenddate = " ";
  $jsenddate .= "|";
  $jsenddate .= $query['bids_remaining'];
   
  }
         if(!$id2) {
  
  $jsenddate = " ";   
  $jsenddate .= "|";
    $jsenddate .= "A";
  
  }
              $jsenddate .= "|";
              
   $query_settings = "select * from PHPAUCTIONXL_proxybid_settings where id='1'";
                             $query_settings2a =  mysql_query ($query_settings);
                                $activated = mysql_result($query_settings2a,0,"activated");
                                
                                 
        if ( $activated == 1 ) {
    if ( $_SESSION["PHPAUCTION_LOGGED_IN"] ) {
 
 
  $query444 = mysql_fetch_array(mysql_query("SELECT proxybidqty FROM PHPAUCTIONXL_proxybid WHERE itemid=$auction_id AND userid=$id2 "));
                           
        if( !empty($query444)) {
 $autobidder_bids_remaining = $query444['proxybidqty'];
 
 $jsenddate .= $autobidder_bids_remaining;
                       }
         if( empty($query444)) {
 $autobidder_bids_remaining = 0;
 
 $jsenddate .= $autobidder_bids_remaining;
                       }                 
                       
 }
       if ( !$_SESSION["PHPAUCTION_LOGGED_IN"] ) {
             $jsenddate .= "login";  
       }
       
  } 
       if ( $activated == 0 ) {
       
       
                  $jsenddate .= "login"; 
    
             }
             
    $savings_buynow_user = $_SESSION["PHPAUCTION_LOGGED_IN"];
              
             if($savings_buynow_user) {
  
    
      $query34543 = "select * from PHPAUCTIONXL_bids2 WHERE bidder='$savings_buynow_user' AND auction='$auction_id'";
$result34543 = mysql_query($query34543);
if($result34543) {
$number_of_bids = mysql_num_rows($result34543);
   }
   
if(empty($result34543)) {
$number_of_bids = 0;
   }   

}    
    
        
        
  $query_settings = "select tax_rate_percentage,average_bid_price from PHPAUCTIONXL_version_1_3 where id='1'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $tax_rate_percentage1 = mysql_result($query_settings2,0,"tax_rate_percentage");
                                 $average_bid_price2 = mysql_result($query_settings2,0,"average_bid_price");

 
    $query_settings = "select shipping_fee,retail,current_bid,bid_credits_reqd from PHPAUCTIONXL_auctions where id='$auction_id'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $shipping_fee2 = mysql_result($query_settings2,0,"shipping_fee");
                                 $retail2 = mysql_result($query_settings2,0,"retail");
                                 $current_bid2 = mysql_result($query_settings2,0,"current_bid"); 
                                 $bid_credits_reqd = mysql_result($query_settings2,0,"bid_credits_reqd");

                                          $query_settings = "select * from PHPAUCTIONXL_version_2_1 where id='1'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $nat_tax_rate2 = mysql_result($query_settings2,0,"nat_tax_rate");                             
                                 $tax_state2 = mysql_result($query_settings2,0,"tax_state"); 

                     $query_settings = "select * from PHPAUCTIONXL_users where id='$id2'";
                             $query_settings2 =  mysql_query ($query_settings);
                                $users_state = mysql_result($query_settings2,0,"prov"); 

if ( empty($average_bid_price2)) {
   $number_of_bids_total = 0;
   }
   
 if ($average_bid_price2 > 0) {     
$number_of_bids_total2 = $number_of_bids * $average_bid_price2;
$number_of_bids_total = $number_of_bids_total2 * $bid_credits_reqd;
  }
  
$total_before_taxes = $shipping_fee2 + $current_bid2;
      
      
    $sales_tax_percentage = 0;
        $st_sales_tax_percentage = 0;
          $taxprice = 0;
          $taxprice3 = 0;
          $taxprice2 = 0;
    
          
if ( $users_state == $tax_state2 && $tax_rate_percentage1 > 0 ) { $taxprice = ( $total_before_taxes * $tax_rate_percentage1 ); 
  
$st_sales_tax_percentage = $tax_rate_percentage1 * 100; 

   //  echo   $taxprice;
     $taxprice = round($taxprice,2);
 
 
       
}

if ( $nat_tax_rate2 > 0 ) {

 $taxprice2 = ( $taxprice + $total_before_taxes ) * $nat_tax_rate2;
        $taxprice2 = round($taxprice2,2);
 $sales_tax_percentage = $sales_tax_percentage + ( $nat_tax_rate2 * 100 );
          $taxprice3 = $taxprice + $taxprice2;
   
          
}

 if ( $taxprice > 0 ) { $tax_total = $taxprice ;}
 if ( $taxprice2 > 0 ) { $tax_total = $taxprice + $taxprice2; }

           // echo $taxprice;
          //  echo $taxprice2;



      
 
   
              $tax_total = round($tax_total,2);
         if( $tax_total > 0 ) { 
$taxes_shipping_total = $tax_total + $shipping_fee2;
           }
            if( $tax_total == 0 ) { 
$taxes_shipping_total = $shipping_fee2;
           }        
           
$savings_total = ( $number_of_bids_total + $taxes_shipping_total + $current_bid2 ) - $retail2;
     $savings_total2 = $savings_total;

if ( $savings_total > 0 ) 

{

 $savings_total = 0;
        
    
}
         
      
if ( $savings_total < 0 ) 

{

 $savings_total = $savings_total * -1;

     
}



    

  if ( $retail2 > 0 ) {
$savings_percentage = $savings_total / $retail2;
     }
     if( $retail2 == 0 ) {
$savings_percentage = 0;
     }

$savings_percentage2 = $savings_percentage * 100;
  $savings_percentage3 = round($savings_percentage2);
  
         
if ( $savings_total2 > 0 ) 

{

 $savings_percentage3 = 0;
        
    
}


     $jsenddate .= "|";
     $jsenddate .= $currency_symbol;
     $jsenddate .= print_money_nosymbol($current_bid2);
    $jsenddate .= "|"; 
      $jsenddate .= "- ";
    $jsenddate .= $ITEM_PAGE_SAVINFS_BIDS_CREDITS_USED." ";
    $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($average_bid_price2);
    $jsenddate .= "|";
    $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($number_of_bids_total);
    $jsenddate .= "|";
    $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($taxes_shipping_total);
    $jsenddate .= "|";
    $jsenddate .= $savings_percentage3;
    $jsenddate .= "% or ";
    $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($savings_total);
    $jsenddate .= "|"; 
    $jsenddate .= "- ";
    $jsenddate .= $ITEM_PAGE_SAVINFS_BIDS_CREDITS_USED." ";
    $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($average_bid_price2);
    $jsenddate .= "|";
    $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($number_of_bids_total);
    $jsenddate .= "|";
  
$total_before_taxes_buynow = ( $retail2 - $number_of_bids_total ) + $shipping_fee2;
  
  
     //echo $total_before_taxes_buynow;
                         
 
        $sales_tax_percentage = 0;
        $st_sales_tax_percentage = 0;
          $taxprice = 0;
          $taxprice3 = 0;
          $taxprice2 = 0;
         // echo   $users_state;
          
          //echo   $tax_rate_percentage1;
          
if ( $users_state == $tax_state2 && $tax_rate_percentage1 > 0 ) { $taxprice = ( $total_before_taxes_buynow * $tax_rate_percentage1 ); 
  
$st_sales_tax_percentage = $tax_rate_percentage1 * 100; 
       $taxprice = round($taxprice,2);
  //echo   $taxprice;
 
 
 
       
}

if ( $nat_tax_rate2 > 0 ) {

 $taxprice2 = ( $taxprice + $total_before_taxes_buynow ) * $nat_tax_rate2;
 
 $sales_tax_percentage = $sales_tax_percentage + ( $nat_tax_rate2 * 100 );
          $taxprice3 = $taxprice + $taxprice2;
   
       $taxprice2 = round($taxprice2,2);   
       //echo  $taxprice2;
}

 if ( $taxprice > 0 ) { $tax_total = $taxprice;}
 if ( $taxprice2 > 0 ) { $tax_total = $taxprice + $taxprice2; }

                   $tax_total = round($tax_total,2);
 
          $tax_total_buynow = $tax_total + $shipping_fee2; 
                  //  echo  $tax_total;
                // echo $shipping_fee2;
   
            $jsenddate .= $currency_symbol;
    $jsenddate .= print_money_nosymbol($tax_total_buynow);
    $jsenddate .= "|";
      
$buynow_total = ( $tax_total_buynow + $retail2 ) - $number_of_bids_total;





$jsenddate .= $currency_symbol;
if ( $buynow_total < 0 ) {
    
    $buynow_total = .01;

}

$jsenddate .= print_money_nosymbol($buynow_total);
$jsenddate .= "|";
                
            
    echo $jsenddate;         




          
          ?> 